﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using DynamicMVVM.SL;

namespace DynamicMVVM.Demo.SLUI
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            Loaded += MainPage_Loaded;
        }
        
        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            var model = new TestModel { Id = 1, Name = "Hasmukh", Address = "1, Abc road, abc, ac12cd" };

            var obj = DynamicObjectCreator.CreateDynamicModel(model);

            var objType = obj.GetType();
            Console.WriteLine(objType.FullName);

            objType.GetProperty("Name").SetValue(obj, "Hasmukh Patel", null);

            var namePropInfo = objType.GetProperty("Id");
            var currVal = namePropInfo.GetValue(obj, null);

            DataContext = obj;
        }
    }

    public class TestModel
    {
        public int Id { get; set; }

        public string Name { get; set; }

        public string Address { get; set; }
    }
}
